package cn.ac.siom.query.dao.impl;

import cn.ac.siom.query.dao.IMediaDao;
import cn.ac.siom.query.vo.Media;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Repository
public class MediaDaoImpl extends SqlSessionDaoSupport implements IMediaDao {

    @Autowired
    public MediaDaoImpl(SqlSessionFactory sqlSessionFactory){
        super.setSqlSessionFactory(sqlSessionFactory);
    }

    @Override
    public boolean doCreate(Media vo) throws SQLException {
        return false;
    }

    @Override
    public boolean doUpdate(Media vo) throws SQLException {
        return false;
    }

    @Override
    public boolean doRemove(Set<?> ids) throws SQLException {
        return false;
    }

    @Override
    public Media findById(Integer id) throws SQLException {
        return null;
    }

    @Override
    public List<Media> findAll() throws SQLException {
        return null;
    }

    @Override
    public List<Media> findAllBySplit(String column, String keyWord, Integer currentPage, Integer lineSize) throws SQLException {
        return null;
    }

    @Override
    public List<Media> find_page(Integer type,Integer rownum, Integer page_id) throws SQLException {
        page_id = rownum * (page_id-1);
        Map<String, Integer> map= new HashMap<>();
        map.put("page_id",page_id);
        map.put("rownum",rownum);
        map.put("type",type);
        return super.getSqlSession().selectList("find_media.image_video", map);

    }

    @Override
    public Integer find_count(Integer type) throws SQLException {
        Map<String, Integer> map= new HashMap<>();
        map.put("type",type);
        return super.getSqlSession().selectOne("find_media.media_count", map);
    }

    @Override
    public Integer find_countAll() throws SQLException {
        return super.getSqlSession().selectOne("find_media.media_countAll");
    }

    @Override
    public boolean insert(Media vo) throws SQLException {
        return super.getSqlSession().insert("find_media.doInsert", vo)>0;
    }

    @Override
    public boolean update(Media vo) throws SQLException {
        return super.getSqlSession().update("find_media.doUpdate",vo)>0;
    }

    @Override
    public boolean delete(List<String> ids) throws SQLException {
        return super.getSqlSession().delete("find_media.doDelete",ids)>0;
    }

    @Override
    public Media find_one(Integer id) throws SQLException {
        Map map=new HashMap<>();
        map.put("id",id);
        return super.getSqlSession().selectOne("find_media.media_list",id);
    }

    @Override
    public List<Media> find_pageAll(Integer rownum, Integer page_id) throws SQLException {
        page_id = rownum * (page_id-1);
        Map<String, Integer> map= new HashMap<>();
        map.put("page_id",page_id);
        map.put("rownum",rownum);
        return super.getSqlSession().selectList("find_media.image_videoAll", map);
    }

    @Override
    public List<Object> find_photo() throws SQLException {
        return super.getSqlSession().selectList("find_media.image");
    }
}
